﻿@{
    ViewData["Title"] = "Create";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form', 'tree', 'util'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table
                , tree = layui.tree
                , layer = layui.layer
                , util = layui.util
                , parentFrameIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引;
            $(function () {
                $.ajax({
                    type: "get",
                    url: "/Console/Menus/GetTreeJson",
                    data: {
                        RoleId: $("#roleid").val(),
                        userType: $("#userType").val()
                    }, // 你的formid
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            //基本演示
                            tree.render({
                                elem: '#test12'
                                , data: item.data
                                , showCheckbox: true  //是否显示复选框
                                , id: 'demoId1'
                                , isJump: false //是否允许点击节点时弹出新窗口跳转
                                , click: false
                            });
                        }
                        layer.closeAll('loading');
                    }
                });
            });
            /* 监听提交 */
            form.on('submit(submit-form)', function (data) {
                var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
                $.ajax({
                    type: "POST",
                    url: "/Console/Menus/SavePower",
                    data: {
                        RoleId: $("#roleid").val(),
                        userType: $("#userType").val(),
                        list: checkedData
                    }, // 你的formid
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            layer.msg("设置成功", { icon: 1, time: 1000 }, function () {
                                parent.layer.close(parentFrameIndex);
                                parent.layui.table.reload("table-datalist");
                            });
                        } else if (item.code == 1) {
                            layer.msg(item.msg, { icon: 2 });
                        } else {
                            layer.msg("保存失败", { icon: 0 });
                        }
                        layer.closeAll('loading');
                    }
                });
                return false;
            });

        });
    </script>
}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="component-form-group">
                <div id="test12" class="demo-tree-more"></div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <input id="roleid" name="roleid" value="@ViewBag.roleid" type="hidden" />
                            <input id="userType" name="userType" value="@ViewBag.userType" type="hidden" />
                            <button class="layui-btn" lay-submit="" lay-filter="submit-form">立即提交</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>